//
//  XQAppViewController.m
//  XQBluetoothSDK
//
//  Created by 包月兴 on 16/7/18.
//  Copyright © 2016年 包月兴. All rights reserved.
//

#import "XQAppViewController.h"
#import "XQFirmwareModel.h"
#import "XQBluetoothSDK.h"
#import "XQNotificationView.h"
@interface XQAppViewController ()
@property (nonatomic,copy) UISwitch *phoneSwitch;
@property (nonatomic,copy) UISwitch *messageSwitch;
@property (nonatomic,copy) UISwitch *wxSwitch;
@property (nonatomic,copy) UISwitch *qqSwitch;
@property (nonatomic,copy) UISwitch *facebookSwitch;
@property (nonatomic,copy) UISwitch *skypeSwith;
@property (nonatomic,copy) UISwitch *twitterSwitch;
@property (nonatomic,copy) UISwitch *whatsSwitch;
@property (nonatomic,copy) UISwitch *lineSwitch;
@property (nonatomic,copy) UISwitch *messagerSwitch;

@end

@implementation XQAppViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"App提醒";
    [self p_initUI];
    _phoneSwitch = self.phoneSwitch;
    _messageSwitch = self.messageSwitch;
    _wxSwitch = self.wxSwitch;
    _qqSwitch = self.qqSwitch;
    _facebookSwitch = self.facebookSwitch;
    _skypeSwith = self.skypeSwith;
    _twitterSwitch= self.twitterSwitch;
    _whatsSwitch = self.whatsSwitch;
    
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
}

#pragma mark ---- getters and setters

-(UISwitch *)phoneSwitch
{
    if (_phoneSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _phoneSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,30,50, 20)];
        if (XQFirmwareModelInstance.cellPhoneSwitch == XQBluetoothFunSwitchClose) {
            _phoneSwitch.on = NO;
        }else
        {
            _phoneSwitch.on = YES;
        }
        [_phoneSwitch addTarget:self action:@selector(phoneSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_phoneSwitch];
    }
    return _phoneSwitch;
}

-(UISwitch *)messageSwitch
{
    if (_messageSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _messageSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,30+30,50, 20)];
        if (XQFirmwareModelInstance.messageSwitch == XQBluetoothFunSwitchClose) {
            _messageSwitch.on = NO;
        }else
        {
            _messageSwitch.on = YES;
        }
        [_messageSwitch addTarget:self action:@selector(messageSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_messageSwitch];
    }
    return _messageSwitch;
}

-(UISwitch *)wxSwitch
{
    if (_wxSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _wxSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,70+30,50, 20)];
        if (XQFirmwareModelInstance.wxSwitch == XQBluetoothFunSwitchClose) {
            _wxSwitch.on = NO;
        }else
        {
            _wxSwitch.on = YES;
        }
        [_wxSwitch addTarget:self action:@selector(wxSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_wxSwitch];
    }
    return _wxSwitch;
}
-(UISwitch *)qqSwitch
{
    if (_qqSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _qqSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,110+30,50, 20)];
        if (XQFirmwareModelInstance.qqSwitch == XQBluetoothFunSwitchClose) {
            _qqSwitch.on = NO;
        }else
        {
            _qqSwitch.on = YES;
        }
        [_qqSwitch addTarget:self action:@selector(qqSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_qqSwitch];
    }
    return _qqSwitch;
}

-(UISwitch *)facebookSwitch
{
    if (_facebookSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _facebookSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,150+30,50, 20)];
        if (XQFirmwareModelInstance.facebookSwitch == XQBluetoothFunSwitchClose) {
            _facebookSwitch.on = NO;
        }else
        {
            _facebookSwitch.on = YES;
        }
        [_facebookSwitch addTarget:self action:@selector(facebookSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_facebookSwitch];
    }
    return _facebookSwitch;
}

-(UISwitch *)skypeSwith
{
    if (_skypeSwith == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _skypeSwith = [[UISwitch alloc] initWithFrame:CGRectMake(x,190+30,50, 20)];
        if (XQFirmwareModelInstance.lineSwitch == XQBluetoothFunSwitchClose) {
            _skypeSwith.on = NO;
        }else
        {
            _skypeSwith.on = YES;
        }
        [_skypeSwith addTarget:self action:@selector(skypeSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_skypeSwith];
    }
    return _skypeSwith;
}

-(UISwitch *)twitterSwitch
{
    if (_twitterSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _twitterSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,230+30,50, 20)];
        if (XQFirmwareModelInstance.twitterSwitch == XQBluetoothFunSwitchClose) {
            _twitterSwitch.on = NO;
        }else
        {
            _twitterSwitch.on = YES;
        }
        [_twitterSwitch addTarget:self action:@selector(twitterSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_twitterSwitch];
    }
    return _twitterSwitch;
}

-(UISwitch *)whatsSwitch
{
    if (_whatsSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _whatsSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,270+30,50, 20)];
        if (XQFirmwareModelInstance.whatsAppSwitch == XQBluetoothFunSwitchClose) {
            _whatsSwitch.on = NO;
        }else
        {
            _whatsSwitch.on = YES;
        }
        [_whatsSwitch addTarget:self action:@selector(whatsSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_whatsSwitch];
    }
    return _whatsSwitch;
}


-(UISwitch *)lineSwitch
{
    if (_lineSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _lineSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,310+30,50, 20)];
        if (XQFirmwareModelInstance.lineSwitch == XQBluetoothFunSwitchClose) {
            _lineSwitch.on = NO;
        }else
        {
            _lineSwitch.on = YES;
        }
        [_lineSwitch addTarget:self action:@selector(lineSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_whatsSwitch];
    }
    return _lineSwitch;
}


-(UISwitch *)messagerSwitch
{
    if (_messagerSwitch == nil) {
        CGFloat x= (self.view.frame.size.width/2 -150)/2 +150;
        _messagerSwitch = [[UISwitch alloc] initWithFrame:CGRectMake(x,310+30,50, 20)];
        if (XQFirmwareModelInstance.lineSwitch == XQBluetoothFunSwitchClose) {
            _messagerSwitch.on = NO;
        }else
        {
            _messagerSwitch.on = YES;
        }
        [_messagerSwitch addTarget:self action:@selector(messagerSwitchChangeEvent:) forControlEvents:UIControlEventValueChanged];
        [self.view addSubview:_whatsSwitch];
    }
    return _messagerSwitch;
}





#pragma mark ------private Method------

-(void)p_initUI
{
    CGFloat x = (self.view.frame.size.width/2 - 150)/2;
    UILabel *phoneLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,30,150,20)];
    [self.view addSubview:phoneLabel];
    phoneLabel.text = @"电话提醒:";
    
    UILabel *messageLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,30+30,150,20)];
    [self.view addSubview:messageLabel];
    messageLabel.text = @"短信提醒:";
    
    UILabel *wxLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 70+30,150,20)];
    [self.view addSubview:wxLabel];
    wxLabel.text = @"微信提醒:";
    
    UILabel *qqLabel = [[UILabel alloc] initWithFrame:CGRectMake(x, 110+30,150,20)];
    [self.view addSubview:qqLabel];
    qqLabel.text = @"QQ提醒:";
    
    UILabel *facebookLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,150+30,150,20)];
    [self.view addSubview:facebookLabel];
    facebookLabel.text = @"facebook提醒:";
    
    UILabel *skypeLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,190+30,150,20)];
    [self.view addSubview:skypeLabel];
    skypeLabel.text = @"skype提醒:";
    
    UILabel *twitterLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,230+30,150,20)];
    [self.view addSubview:twitterLabel];
    twitterLabel.text = @"twitter提醒:";
    
    UILabel *whatsLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,270+30,150,20)];
    [self.view addSubview:whatsLabel];
    whatsLabel.text = @"whatsApp提醒:";
    
    
    UILabel *lineLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,310+30,150,20)];
    [self.view addSubview:lineLabel];
    whatsLabel.text = @"line提醒:";
    
    UILabel *messagerLabel = [[UILabel alloc] initWithFrame:CGRectMake(x,350+30,150,20)];
    [self.view addSubview:messagerLabel];
    whatsLabel.text = @"messager提醒:";
    
}

#pragma mark 来电提醒
-(void)phoneSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSCellPhoneWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"来电提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"来电提醒打开失败"];
            _phoneSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSCellPhoneWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"来电提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
             [XQNotificationView showWithActiveStyle:NO andMessage:@"来电提醒关闭失败"];
            _phoneSwitch.on = YES;
        }];
    }
}

#pragma mark  信息提醒
-(void)messageSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSMessageWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"短信提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"短信提醒打开失败"];
            _messageSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSMessageWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"短信提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"短信提醒关闭失败"];
            _messageSwitch.on = YES;
        }];
    }
}

#pragma mark 微信提醒
-(void)wxSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSWXWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"微信提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"微信提醒打开失败"];
            _wxSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSWXWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"微信提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"微信提醒关闭成功"];
            _wxSwitch.on = YES;
        }];
    }
}

#pragma mark QQ提醒
-(void)qqSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSQQWithType:XQBluetoothFunSwitchOpen success:^{
             [XQNotificationView showWithActiveStyle:NO andMessage:@"QQ提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
             [XQNotificationView showWithActiveStyle:NO andMessage:@"QQ提醒打开失败"];
            _qqSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSQQWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"QQ提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"QQ提醒关闭失败"];
            _qqSwitch.on = YES;
        }];
    }
}

#pragma mark facebook提醒
-(void)facebookSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSFacebookWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"Facebook提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
             [XQNotificationView showWithActiveStyle:NO andMessage:@"Facebook提醒打开失败"];
            _facebookSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSFacebookWithType:XQBluetoothFunSwitchClose success:^{
             [XQNotificationView showWithActiveStyle:NO andMessage:@"Facebook提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"Facebook提醒关闭失败"];
            _facebookSwitch.on = YES;
            
        }];
    }
}

#pragma  mark skype提醒

-(void)skypeSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSSkypeWithType:XQBluetoothFunSwitchOpen success:^{
             [XQNotificationView showWithActiveStyle:NO andMessage:@"skype提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"skype提醒打开失败"];
            _skypeSwith.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSSkypeWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"skype提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"skype提醒关闭失败"];
            _skypeSwith.on = YES;
        }];
    }
}

#pragma mark twitter提醒

-(void)twitterSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSTwitterWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"twitter提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"twitter提醒打开失败"];
            _twitterSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSTwitterWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"twitter提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"twitter提醒关闭失败"];
            _twitterSwitch.on = YES;
        }];
    }
}

#pragma mark --- whatsApp

-(void)whatsSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSWhatsAppWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"whatsApp提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"whatsApp提醒打开失败"];
            _whatsSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSWhatsAppWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"whatsApp提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"whatsApp提醒关闭失败"];
            _whatsSwitch.on = YES;
        }];
    }
}


-(void)lineSwitchChangeEvent:(UISwitch *)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSLineWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"line提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"line提醒打开失败"];
            _whatsSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSLineWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"line提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"line提醒关闭失败"];
            _whatsSwitch.on = YES;
        }];
    }
}


-(void)messagerSwitchChangeEvent:(UISwitch*)changeSwitch
{
    if (changeSwitch.on) {
        [XQBleSDKInstance syncANCSMessagerWithType:XQBluetoothFunSwitchOpen success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"messager提醒打开成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"messager提醒打开失败"];
            _whatsSwitch.on = NO;
        }];
    }else
    {
        [XQBleSDKInstance syncANCSMessagerWithType:XQBluetoothFunSwitchClose success:^{
            [XQNotificationView showWithActiveStyle:NO andMessage:@"messager提醒关闭成功"];
        } failure:^(XQBluetoothError *error) {
            [XQNotificationView showWithActiveStyle:NO andMessage:@"messager提醒关闭失败"];
            _whatsSwitch.on = YES;
        }];
    }
}


@end
